package com.jiyu.controller;

import com.jiyu.entity.User;
import com.jiyu.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Objects;

@Slf4j
@Controller
public class WebSocketController {

    @Autowired
    UserService userService;

/*
    @RequestMapping("/websocket/{name}")
    public String webSocket(@PathVariable String name, Model model) {
        try {
            log.info("已经跳转到websocket的页面上");
            model.addAttribute("username", name);
            return "chatroom";
        } catch (Exception e) {
            log.info("跳转到websocket的页面上发生异常，异常信息：" + e.getMessage());
            return "error";
        }
    }
    */

    @RequestMapping("/userInfo")
    @ResponseBody
    public User userInfo(@RequestParam String username){
        if(userService.isExist(username)){
            User user = userService.getByUserName(username);

            return user;
        }
        return null;
    }

}
